//
//  HLTabBarViewController.m
//  HLAerospace
//
//  Created by hulian-ios on 17/8/29.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//


#import "HLTabBarViewController.h"
#import "HLNavigationController.h"
#import "HLHomeViewController.h"
#import "HLSubjectViewController.h"
#import "HLMineViewController.h"

@interface HLTabBarViewController ()

@end

@implementation HLTabBarViewController

#pragma mark - 初始化
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /**** 设置所有UITabBarItem的文字属性 ****/
    [self setupItemTitleTextAttributes];
    
    /**** 添加子控制器 ****/
    [self setupChildViewControllers];
    
}

/**
 *  设置所有UITabBarItem的文字属性
 */
- (void)setupItemTitleTextAttributes
{
    UITabBarItem *item = [UITabBarItem appearance];
    // 普通状态下的文字属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateSelected];
}

/**
 *  添加子控制器
 */
- (void)setupChildViewControllers
{
    [self setupOneChildViewController:[[HLNavigationController alloc] initWithRootViewController:[[HLHomeViewController alloc] init]] title:@"首页" image:@"tabBar_home_icon" selectedImage:@"tabBar_home_click_icon"];
    
    [self setupOneChildViewController:[[HLNavigationController alloc] initWithRootViewController:[[HLSubjectViewController alloc] init]] title:@"课程" image:@"tabBar_subject_icon" selectedImage:@"tabBar_subject_click_icon"];
    
    [self setupOneChildViewController:[[HLNavigationController alloc] initWithRootViewController:[[HLMineViewController alloc] init]] title:@"我的" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}

/**
 *  初始化一个子控制器
 *
 *  @param vc            子控制器
 *  @param title         标题
 *  @param image         图标
 *  @param selectedImage 选中的图标
 */
- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    vc.tabBarItem.title = title;
    if (image.length) { // 图片名有具体值
        vc.tabBarItem.image = [UIImage imageNamed:image];
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    }
    [self addChildViewController:vc];
}



@end
